package com.kch.web.controller.portal;


import com.alibaba.fastjson.JSON;
import com.kch.common.core.controller.BaseController;
import com.kch.common.core.domain.AjaxResult;
import com.kch.framework.util.ShiroUtils;
import com.kch.system.domain.SysUser;
import com.kch.system.service.ContentService;
import com.kch.system.vo.PortalReqVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.validation.Valid;

@Controller
@RequestMapping("/content")
@Api(tags = "配置相关查询")
@ResponseBody
public class ContentController extends BaseController {

    @Autowired
    private ContentService contentService;

    /**
     * 需要查询详情的有FA,XQ,ZJ,WT, HY,HD,PX,JU
     */
    @ApiOperation("根据code获取配置信息")
    @PostMapping("/getDataByCode")
    public AjaxResult getDataByCode(@RequestBody @Valid PortalReqVO req) {
        SysUser sysUser = ShiroUtils.getSysUser();
        return AjaxResult.success(contentService.getDataByCode(req, sysUser));
    }

    /**
     * 获取配置详情
     *
     * @param req
     * @return
     */
    @ApiOperation("根据code获取配置信息详情")
    @PostMapping("/getDataByCodeDetail")
    public AjaxResult getDataByCodeDetail(@RequestBody @Valid PortalReqVO req) {
        SysUser sysUser = ShiroUtils.getSysUser();
        return AjaxResult.success(contentService.getDataByCodeDetail(req, sysUser));
    }


    /**
     * 获取首页找方案、发需求、提问题的十条数据
     */
    @ApiOperation("获取首页轮播")
    @GetMapping("/getDataIndexCarousel")
    public AjaxResult getDataIndexCarousel() {
        return AjaxResult.success(contentService.getDataIndexCarousel());
    }


    @ApiOperation("根据code获取配置信息详情, type:false:查询标签; true查询科技管家头部'战略性新兴产业集群'和'未来产业'; " +
            "返回值type为1是战略性新兴产业集群, type为2是未来产业")
    @GetMapping("/getTags")
    public AjaxResult getTags(@RequestParam("code") String code,
                              @RequestParam(value = "type", required = false) Boolean type) {
        return AjaxResult.success(contentService.getTagList(code, type));
    }

}
